import rclpy
from rclpy.node import Node
class ParamServerPyNode(Node):
    def __init__(self,node_name="param_server_py_node"):
        super().__init__(node_name,allow_undeclared_parameters=True)
        self.get_logger().info('ParamServerPyNode创建')
    def add_param(self):
        self.declare_parameter("car_name","tiger")
        self.declare_parameter("width",1.55)
        self.declare_parameter("wheels",5)
        self.get_logger().info("----------------增----------------")
    def delete_param(self):
        self.get_logger().info("----------------删----------------")
        # self.undeclare_parameter() 要求两点 一个是true  一个是set_parameter  
    def update_param(self):
        self.get_logger().info("----------------改----------------")
        car_name="car_name"
        self.set_parameters([rclpy.Parameter(car_name,value="mouse")])
        car_param: rclpy.Parameter=self.get_parameter(car_name)
        self.get_logger().info('修改后：%s = %s'%(car_param.name,car_param.value))

    def get_param(self):
        # param.type_ == Parameter.Type.NOT_SET
        car_name="car_name"
        car_param: rclpy.Parameter=self.get_parameter(car_name)
        self.get_logger().info('%s = %s'%(car_param.name,car_param.value))
        #
        params: list[rclpy.Parameter]=self.get_parameters(["wheels","width"])
        for param in params:
            param:rclpy.Parameter=param
            self.get_logger().info('%s = %s'%(param.name,param.value))
        self.get_logger().info("----------------查----------------")            
def main():
    rclpy.init()
    server_node: ParamServerPyNode = ParamServerPyNode()
    server_node.add_param()
    server_node.get_param()
    server_node.update_param()
    # server_node.get_param()
    # server_node.delete_param()
    rclpy.spin(server_node)
    rclpy.shutdown()


if __name__ == '__main__':
    main()